package com.sleet.yuemiao.even;

import com.sleet.yuemiao.pojo.CustInfo;
import com.sleet.yuemiao.service.YueMiaoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: yuemiao
 * @ClassName DemoEventListener
 * @description:
 * @author: Liyongxing
 * @create: 2021-12-24 20:59
 **/
@Component
@Slf4j
public class DemoEventListener implements ApplicationListener<DemoEvent> {
    @Resource
    YueMiaoService yueMiaoService;

    //使用注解@Async支持 这样不仅可以支持通过调用，也支持异步调用，非常的灵活，
    @Async
    @Override
    public void onApplicationEvent(DemoEvent event) {
        CustInfo custInfoSouce =(CustInfo) event.getSource();
        try {
            CustInfo custInfo =(CustInfo) custInfoSouce.deepClone();
            CustInfo setCookieCust = yueMiaoService.getCaptcha(custInfo);
            if(StringUtils.isEmpty(setCookieCust.getCookie())){
                Object save20 = yueMiaoService.Save20(custInfo);
                log.info("save20 预约结果response：[{}]",save20);
            }
            System.out.println("监听器出发 = " + custInfo+"/n");
        } catch (Exception e) {
            e.printStackTrace();
        }

        System.out.println(",消息摘要为:"+event.getMsg());
    }

}
